package rs.dalao.syc.doctor.prescription.service.impl;/*
 *   @author:Casin
 *   @date:2023/8/12
 *   @code:
 */

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import rs.dalao.syc.common.pojo.authentication.CurrentPrincipal;
import rs.dalao.syc.common.pojo.vo.PageData;
import rs.dalao.syc.doctor.prescription.dao.persist.repository.IPrescriptionRepository;
import rs.dalao.syc.doctor.prescription.pojo.entity.Prescription;
import rs.dalao.syc.doctor.prescription.pojo.param.PresAddNewParam;
import rs.dalao.syc.doctor.prescription.pojo.vo.PatientListVO;
import rs.dalao.syc.doctor.prescription.pojo.vo.PatientNameVO;
import rs.dalao.syc.doctor.prescription.service.IPrescriptionService;

import java.util.List;

@Service
@Slf4j
public class PrescriptionServiceImpl implements IPrescriptionService {
    @Autowired
    IPrescriptionRepository repository;
    @Value("10")
    private Integer defaultQueryPageSize;

    @Override
    public List<PatientNameVO> getAll() {
        return repository.getAllPatient();
    }

    @Override
    public int PrescriptionAddNew(PresAddNewParam addNewParam, @AuthenticationPrincipal CurrentPrincipal currentPrincipal) {
        log.debug("开始处理【开处方】的业务，参数：{}", addNewParam);
        Prescription prescription=new Prescription();
        BeanUtils.copyProperties(addNewParam,prescription);
        prescription.setIsPaid(0);
        prescription.setIsDisplayDoc(1);
        prescription.setIsDisplayUser(1);
        prescription.setDoctorId(currentPrincipal.getId());
        return repository.addNew(prescription);
    }

    @Override
    public int update(Long id) {
        Prescription prescription=new Prescription();
        prescription.setIsDisplayDoc(0);
        return repository.update(prescription,id);
    }

    @Override
    public PageData<PatientListVO> getPatientList(Long doctorId,Integer pageNum) {
        log.debug("开始处理【查询用户列表】的业务，页码：{}", pageNum);
        return repository.getPatientList(doctorId, pageNum, defaultQueryPageSize);
    }
}
